package com.tom.architect02.structure.hashmap;

import java.util.Objects;

/**
 * Added by Tom on 2024/02/20.
 */
public class TestHashMap {

    public static void main(String[] args) {

        HashMap<Integer, Student> map = new HashMap<>();
        for (int i = 0; i < 8; i++) {
            map.put(i, new Student("Tom " + i));
        }
        for (int i = 0; i < 8; i++) {
            System.out.println(map.get(i).name);
        }
    }

    public static class Student {
        String name;
        public Student(String name) {
            this.name = name;
        }

        @Override
        public boolean equals(Object o) { // 复写equals方法。
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Student student = (Student) o;
            return name.equals(student.name);
        }

        @Override
        public int hashCode() {
            return Objects.hash(name);
        }
    }

}
